<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>首页详情</title>
<%@ include file="common/base.jsp" %>
</head>

<body>
<!--head-->
<div id="head">
	<%@ include file="common/head.jsp" %>
</div>
<!--head end-->
<!--container-->
<div id="container">
    <div id="pageId">01</div>
	<!--sidebar-->
    <%@ include file="common/menu.jsp" %>
    <!--sidebar-->
    <!--main-->
    <div class="main">
    	<div class="location" style="background-position:22px 12px;">
    		<a href="main">首页</a>
			<span>&gt;</span>
        	数据汇总
        </div>
        <!--content-->
        <div class="content">
            <div class="channel_manage">
            	<div class="info_container">
                    <label>彩种：
						<select id="gameId">
							<option value="">全部</option>
							<c:forEach items="${games }" var="game">
								<option value="${game.gameId }">${game.gameName }</option>
							</c:forEach>
						</select>	
                    </label>选择时间：
                    <input id="startDate" type="text" class="text" value="${startDate }" style="width:125px;margin-right:5px;" onFocus="WdatePicker({dateFmt:'yyyy-MM-dd',minDate:'1990-01-01'})" readonly="readonly"/>
                    	至
                    <input id="endDate" type="text" class="text" value="${endDate }" style="width:125px;margin-left:5px;" onFocus="WdatePicker({dateFmt:'yyyy-MM-dd',minDate:'1990-01-01'})" readonly="readonly"/>
                    <button id="queryButton" type="button" class="btn btn_search"></button>
                </div>
                <div id="tableResult">
	                <table id="printTable" class="table_type1">
	                	<thead>
	                    	<tr>
	                        	<th>序号</th>
	                        	<th>彩种</th>
	                        	<th>销量总额 </th>
	                            <th>中奖总额</th>
	                            <th>渠道充值总额</th>
	                            <th>彩民充值总额</th>
	                            <th>渠道提现总额</th>
	                            <th>彩民提现总额</th>
	                        </tr>
	                    </thead>
	                    <tbody id="bodyResult">
	                    </tbody>
	                </table>
	                <div class="page">
	                    <div class="pageNum">
	                        <button type="button" class="btn btn_export"  onclick="exportCSV();">导出</button>
	                        <button type="button" class="btn btn_print" onclick="doPrint('数据汇总');">打印</button>
	                    </div>
	                </div>
                </div>
            </div>
        </div>
        <!--content-->
        <!--foot-->
        <div id="foot">
        	<jsp:include page="common/foot.jsp"></jsp:include>
        </div>
        <!--foot-->
    </div>
    <!--main-->
</div>
<!--container-->
<script src="${pageContext.request.contextPath}/static/js/basic.js"></script>
<script type="text/javascript">
	$(function(){
		$("#queryButton").click(function(){
			queryMainDetail();
		});
		queryMainDetail();
	});
	
	function getParam(){
		var param = "";
		var gameId = $("#gameId").val().trim();
		if(gameId != "")
			param += (param == "" ? "gameId=" : "&gameId=") + gameId;
		
		var startDate = $("#startDate").val().trim();
		if(startDate != "")
			param += (param == "" ? "startDate=" : "&startDate=") + startDate;
		
		var endDate = $("#endDate").val().trim();
		if(endDate != "")
			param += (param == "" ? "endDate=" : "&endDate=") + endDate;
		return param;
	}
	
	function queryMainDetail(){
		var param = getParam();
		$.ajax({
			url:"${pageContext.request.contextPath }/mainDetail/query",
			type:'post',
			data:param,
			beforeSend:function(XMLHttpRequest){
				$("#tableResult").showLoading();
				flagTable = true;
	        },
	        error:function(XMLHttpRequest, textStatus, errorThrown){
	        	prompt.alert("系统错误");
	        	$("#tableResult").hideLoading();
	        },
	        success:function(data){
	        	$("#tableResult").hideLoading();
	        	$("#bodyResult").html("");
	        	loadTableResult(data);
	        	if($("#bodyResult").html() == ''){
	        		$("#bodyResult").html("<tr class=\"no_data\"><td colspan=\"14\">没有符合您要查询的数据！</td></tr>");
	        		$(".page").hide();
	        		if($("#tfoot").html() != null){
	            		$("#tfoot").hide();
	            	}
	        	}else{
	        		$(".page").show();
	        		if($("#tfoot").html() != null){
	            		$("#tfoot").show();
	            	}
	        	}
	        }
		});
	}
		
	function loadTableResult(data){
		var dataList = data.dataList;
		if(dataList != null && dataList.length > 0){
			var row = dataList.length + 1;
			for(var i in dataList){
				var trContent_before = "<tr>"+
				"<td>" + (parseInt(i) + 1) + "</td>" +
	            "<td>" + dataList[i].gameName + "</td>" +
	            "<td>" + fmoney(dataList[i].sale, 2, ',') + "</td>" +
	            "<td>" + fmoney(dataList[i].prize, 2, ',') + "</td>";
	            var trContent_after = "</tr>";
	            if(i == 0){
	            	trContent_after = "<td  rowspan=" + row + ">" + fmoney(data.fund.partnerCharge, 2, ',') + "</td>" +
	            		"<td  rowspan=" + row + ">" + fmoney(data.fund.userCharge, 2, ',') + "</td>" +
	            		"<td  rowspan=" + row + ">" + fmoney(data.fund.partnerEncash, 2, ',') + "</td>" +
	            		"<td  rowspan=" + row + ">" + fmoney(data.fund.userEncash, 2, ',') + "</td>" +
			            trContent_after;
	            }
	            $("#bodyResult").append(trContent_before + trContent_after);
			}
			var sum = data.sum;
			var trContent = "<tr>"+
			"<td>总计</td>" +
	        "<td></td>" +
	        "<td>" + fmoney(sum.sale, 2, ',') + "</td>" +
	        "<td>" + fmoney(sum.prize, 2, ',') + "</td>" +
	        "</tr>";
	        $("#bodyResult").append(trContent);
		}
	}
	
	function getContent(){
		var tableHtml = document.getElementById("printTable").innerHTML;
		return tableHtml;
	}
	
	function exportCSV(){
		var param = getParam();
		document.location.href ="${pageContext.request.contextPath}/mainDetail/export?" + param;
	}
	
</script>
</body>
</html>
